#include "bubblesort.h"

BubbleSort::BubbleSort(QObject *parent):
    IAlgo(parent)
{

}

QString BubbleSort::name()
{
    return "Bubble Sort";
}

void BubbleSort::run()
{
    _run_time = 0;
    QVector<int> &data = _data->GetData();
    for(int i = data.size() - 1; i >= 0; --i){
        for(int j = 0; j < i; ++j){
            if(data[j] > data[j+1]){
                qSwap(data[j], data[j+1]);
                _data->Refresh();
            }
            _run_time++;
        }
    }
}
